<template>
  <div class="register-wrapper">
    <div class="register-container">
      <h2>用户注册</h2>
      <form @submit.prevent="handleSubmit" class="register-form">
        <div class="form-group">
          <input
              type="text"
              id="username"
              v-model="form.username"
              required
              placeholder="用户名"
              class="form-input"
          />
        </div>

        <div class="form-group">
          <input
              type="tel"
              id="phone"
              v-model="form.phone"
              required
              placeholder="手机号"
              class="form-input"
          />
        </div>

        <div class="form-group">
          <input
              type="password"
              id="password"
              v-model="form.password"
              required
              placeholder="密码"
              minlength="6"
              class="form-input"
          />
        </div>

        <div class="form-group">
          <input
              type="password"
              id="confirmPassword"
              v-model="form.confirmPassword"
              required
              placeholder="确认密码"
              :class="['form-input', { 'error': !passwordMatch && form.confirmPassword }]"
          />
          <span v-if="!passwordMatch && form.confirmPassword" class="error-message">
            两次输入的密码不一致
          </span>
        </div>

        <button type="submit" :disabled="!formValid" class="submit-btn">注册</button>
      </form>
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      form: {
        username: '',
        phone: '',
        password: '',
        confirmPassword: ''
      }
    }
  },
  computed: {
    passwordMatch() {
      return this.form.password === this.form.confirmPassword
    },
    formValid() {
      return (
          this.form.username &&
          this.form.phone &&
          this.form.password &&
          this.passwordMatch
      )
    }
  },
  methods: {
    handleSubmit() {
      if (!this.formValid) return

      console.log('注册信息:', this.form)
      alert('注册成功！')

      this.form = {
        username: '',
        phone: '',
        password: '',
        confirmPassword: ''
      }
    }
  }
}
</script>

<style scoped>
.register-wrapper {
  height: 100vh;
  display: flex;
  justify-content: center;
  align-items: center;
  background-color: #f0f2f5;
  background-image: url('../assets/about-us/top-bg.jpg');
  background-size: cover;
}

.register-container {
  width: 100%;
  max-width: 400px;
  padding: 40px;
  background: white;
  border-radius: 12px;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.08);
}

h2 {
  text-align: center;
  color: #333;
  margin-bottom: 30px;
  font-size: 24px;
  font-weight: 600;
}

.register-form {
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.form-input {
  width: 100%;
  padding: 14px 16px;
  border: 1px solid #e0e0e0;
  border-radius: 8px;
  font-size: 15px;
  transition: all 0.3s;
  box-sizing: border-box;
}

.form-input:focus {
  border-color: #42b983;
  outline: none;
  box-shadow: 0 0 0 2px rgba(66, 185, 131, 0.2);
}

.form-input.error {
  border-color: #ff4444;
}

.error-message {
  color: #ff4444;
  font-size: 13px;
  margin-top: 5px;
  display: block;
}

.submit-btn {
  width: 100%;
  padding: 14px;
  background-color: #42b983;
  color: white;
  border: none;
  border-radius: 8px;
  font-size: 16px;
  font-weight: 500;
  cursor: pointer;
  transition: background-color 0.3s;
  margin-top: 10px;
}

.submit-btn:hover {
  background-color: #369f6b;
}

.submit-btn:disabled {
  background-color: #cccccc;
  cursor: not-allowed;
}

/* 响应式设计 */
@media (max-width: 480px) {
  .register-container {
    padding: 30px 20px;
  }

  .form-input {
    padding: 12px 14px;
  }
}
</style>